package com.ruoyi.project.channel.payerBusinessInfo.controller;

import java.util.List;

import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.payerBusinessInfo.domain.PayerBusinessInfo;
import com.ruoyi.project.channel.payerBusinessInfo.service.IPayerBusinessInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 支付商商户信息操作处理
 *
 * @author CAIN
 * @date 2019-06-29
 */
@Controller
@RequestMapping("/channel/payerBusinessInfo")
public class PayerBusinessInfoController extends BaseController {
    private String prefix = "channel/payerBusinessInfo";

    @Autowired
    private IPayerBusinessInfoService payerBusinessInfoService;
    @Autowired
    private IUserService userService;
    @RequiresPermissions("channel:payerBusinessInfo:view")
    @GetMapping()
    public String payerBusinessInfo() {
        return prefix + "/payerBusinessInfo";
    }

    /**
     * 查询支付商商户列表
     */
    @RequiresPermissions("channel:payerBusinessInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PayerBusinessInfo payerBusinessInfo) {
        startPage();
        List<PayerBusinessInfo> list = payerBusinessInfoService.selectPayerBusinessInfoList(payerBusinessInfo);
        return getDataTable(list);
    }


    /**
     * 导出支付商商户列表
     */
    @RequiresPermissions("channel:payerBusinessInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PayerBusinessInfo payerBusinessInfo) {
        List<PayerBusinessInfo> list = payerBusinessInfoService.selectPayerBusinessInfoList(payerBusinessInfo);
        ExcelUtil<PayerBusinessInfo> util = new ExcelUtil<PayerBusinessInfo>(PayerBusinessInfo.class);
        return util.exportExcel(list, "payerBusinessInfo");
    }

    /**
     * 新增支付商商户
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        List<User> user = userService.selectPayerlList(new User());
        mmap.put("payers",user);
        return prefix + "/add";
    }

    /**
     * 新增保存支付商商户
     */
    @RequiresPermissions("channel:payerBusinessInfo:add")
    @Log(title = "支付商商户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PayerBusinessInfo payerBusinessInfo) {
        return toAjax(payerBusinessInfoService.insertPayerBusinessInfo(payerBusinessInfo));
    }

    /**
     * 修改支付商商户
     */
    @GetMapping("/edit/{payerBusinessId}")
    public String edit(@PathVariable("payerBusinessId") Long payerBusinessId, ModelMap mmap) {
        PayerBusinessInfo payerBusinessInfo = payerBusinessInfoService.selectPayerBusinessInfoById(payerBusinessId);
        mmap.put("payerBusinessInfo", payerBusinessInfo);
        List<User> user = userService.selectPayerlList(new User());
        mmap.put("payers",user);
        return prefix + "/edit";
    }

    /**
     * 修改保存支付商商户
     */
    @RequiresPermissions("channel:payerBusinessInfo:edit")
    @Log(title = "支付商商户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PayerBusinessInfo payerBusinessInfo) {
        return toAjax(payerBusinessInfoService.updatePayerBusinessInfo(payerBusinessInfo));
    }

    /**
     * 删除支付商商户
     */
    @RequiresPermissions("channel:payerBusinessInfo:remove")
    @Log(title = "支付商商户", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(payerBusinessInfoService.deletePayerBusinessInfoByIds(ids));
    }

}
